﻿#include "Generation/Engine/Core/VecSet.h"

FVecSet::FVecSet(int width, int height)
{
	Values = new FArray2D<int>(width, height, 0);
	XMin = width; //反向操作，确保加入的第一个点，就是它的最小最大范围。
	XMax = 0;
	YMin = height;
	YMax = 0;
}

void FVecSet::Add(FVec* pos)
{
	Values->Set(pos, Sentinel);
	XMin = FMath::Min(XMin, pos->x);
	XMax = FMath::Max(XMax, pos->x);
	YMin = FMath::Min(YMin, pos->y);
	YMax = FMath::Max(YMax, pos->y);
}

void FVecSet::Clear()
{
	Sentinel++;
	// TODO: Check for overflow?

	XMin = Values->width();
	XMax = 0;
	YMin = Values->height();
	YMax = 0;
}

bool FVecSet::Contains(FVec* pos)
{
	return Values->Get(pos) == Sentinel;
}